grid = [["1", "1", "1"], ["0", "1", "0"], ["1", "1", "1"]]

max_r = len(grid)
max_c = len(grid[0])
res = 0


def dfs(row, column):
    grid[row][column] = "0"
    if (row + 1) < max_r and grid[row + 1][column] == "1":
        dfs(row + 1, column)
    if (row - 1) >= 0 and grid[row - 1][column] == "1":
        dfs(row - 1, column)
    if (column + 1) < max_c and grid[row][column + 1] == "1":
        dfs(row, column + 1)
    if (column - 1) >= 0 and grid[row][column - 1] == "1":
        dfs(row, column - 1)


for i in range(max_r):
    for j in range(max_c):
        if grid[i][j] == "1":
            dfs(i, j)
            res += 1

print(res)
